//
//  RootView.m
//  项目三
//
//  Created by rimi1 on 2016/12/7.
//  Copyright © 2016年 Wangxingqian. All rights reserved.
//

#import "NBButton.h"

@implementation NBButton

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self addSubview:self.left];
        [self addSubview:self.right];
    }
    return self;
}

#pragma mark - respondsTo..

- (void)respondsToButton:(UIButton *)sender {
    if (sender.selected) {
        return;
    }
    
    if (self.headBlock) {
        self.headBlock(sender);
    }
}

#pragma mark - get

- (UIButton *)left {
    
    if (!_left) {
        
        _left = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, self.bounds.size.width/2, self.bounds.size.height)];
        _left.layer.borderColor = [UIColor whiteColor].CGColor;
        _left.layer.borderWidth = 1;
        _left.backgroundColor = [UIColor whiteColor];
        _left.selected = YES;
        _left.tag = 100;
        [_left setTitleColor:kCOLOR_RGB(106, 200, 248, 1) forState:UIControlStateSelected];
        [_left setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_left addTarget:self action:@selector(respondsToButton:) forControlEvents:UIControlEventTouchUpInside];
        _left.titleLabel.font = [UIFont systemFontOfSize:15];
        
    }
    return _left;
}

- (UIButton *)right {
    
    if (!_right) {
        
        _right = [[UIButton alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.left.frame), 0, CGRectGetWidth(self.left.bounds), CGRectGetHeight(self.left.bounds))];
        _right.layer.borderColor = self.left.layer.borderColor;
        _right.layer.borderWidth = self.left.layer.borderWidth;
        _right.tag = 101;
        [_right setTitleColor:kCOLOR_RGB(106, 200, 248, 1) forState:UIControlStateSelected];
        [_right setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_right addTarget:self action:@selector(respondsToButton:) forControlEvents:UIControlEventTouchUpInside];
        _right.titleLabel.font = [UIFont systemFontOfSize:15];
        
    }
    return _right;
}

@end












